<template>
  <div>
    <Frame
      class="frame"
      flexType="flex"
      size="small-2"
      title="设置主机号"
      content2="content2"
      :visible="dialogVisible"
    >
      <template #default>
        <el-form
          :model="addForm"
          :rules="rules"
          ref="refForm"
          label-width="100px"
          inline
        >
          <el-form-item size="small" label="主机号" prop="hostNumber">
            <el-input
              v-model="addForm.hostNumber"
              clearable
              placeholder="请输入主机号"
              size="small"
              style="width: 300px"
              maxlength="20"
            >
            </el-input>
          </el-form-item>
        </el-form>
      </template>
      <template #footer>
        <div class="footer-btns">
          <el-button size="small" @click="closeDialog">取消</el-button>
          <el-button size="small" @click="submit" v-preventReClick="1000"
            >确认</el-button
          >
        </div>
      </template>
    </Frame>
  </div>
</template>

<script>
import Frame from "./frame.vue";
import { reqUtdSetHostNumber } from "@api/api.js";
import {
  validateNumber,
} from "@utils/validate";
import { mapState } from "vuex";

export default {
  props: ["deviceCode_c"],
  components: { Frame },
  data() {
    return {
      dialogVisible: false,
      addForm: {
        hostNumber: "",
      },
      rules: {
        hostNumber: [
          { required: true, message: "请输入主机号", trigger: "blur" },
          {
            validator: validateNumber,
            trigger: "blur",
          },
        ],
      },
    };
  },
  watch: {},
  computed: {
    ...mapState(["user"]),
  },
  mounted() {},
  methods: {
    // 点击绑定
    submit() {
      this.$refs.refForm.validate(async (valid) => {
        if (!valid) return;
        const res = await reqUtdSetHostNumber({
          deviceCode: this.deviceCode_c,
          hostNumber: this.addForm.hostNumber,
        });
        if (res.code !== 20000) return this.$modal.notifyWarning(res.message);
        this.$modal.notifySuccess("设置成功");
        this.$emit("update");
        this.closeDialog();
      });
    },

    // 点击关闭弹框
    closeDialog() {
      this.$refs.refForm.resetFields();
      this.addForm.hostNumber = "";
      this.$parent.showShade = false;
      this.dialogVisible = false;
    },
  },
};
</script>

<style lang="less" scoped>
@import url("../../../../views/common.less");
// input后面的查询按钮
::v-deep .el-input-group__append {
  color: #fff;
  border: none;
  background-color: #7367f0;
}

.tip {
  color: #999;
  font-size: 12px;
  line-height: 22px;
  padding-left: 30px;
  .label {
  }
}

.footer-btns {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
</style>
